package com.software.loginregister.fragment.community;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.software.loginregister.R;
import com.software.loginregister.adapter.HotPostAdapter;
import com.software.loginregister.entity.Post;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;


public class HotCommunityFragment extends Fragment {
    private RecyclerView rvHotPosts;
    private HotPostAdapter adapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_hot_community, container, false);
        initViews(view);
        initData();
        return view;
    }

    private void initViews(View view) {
        rvHotPosts = view.findViewById(R.id.rv_community_hot_posts);
        // 添加分割线
        rvHotPosts.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
        rvHotPosts.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter = new HotPostAdapter();
        rvHotPosts.setAdapter(adapter);
    }

    private void initData() {
        List<Post> posts = new ArrayList<>();

        // Create Date objects for the posts
        Calendar calendar = Calendar.getInstance();

        // First post - 19 hours ago
        calendar.setTime(new Date());
        calendar.add(Calendar.HOUR, -19);
        posts.add(new Post("内向的水杯", null, "四川麻辣烫最上个月刚从四川麻辣烫回来😭😭😭😭", calendar.getTime(), 3, 57));

        // Second post - 13 hours ago
        calendar.setTime(new Date());
        calendar.add(Calendar.HOUR, -13);
        posts.add(new Post("cheery spring", null, "一进来就大声说话。。。", calendar.getTime(), 24, 39));

        // Third post - 13 hours ago
        calendar.setTime(new Date());
        calendar.add(Calendar.HOUR, -13);
        posts.add(new Post("单纯的毛衣", null, "真的没人和我拼买一斤送半斤的香香鸡吗😭", calendar.getTime(), 0, 33));

        adapter.setData(posts);
    }
}